DPQueue is now a two-lock concurrent queue.
[hom.git] / Tests / Unit Tests / DPDictionaryTests.m
blob7d9c41784151debdb2814e4d8c34dbce14bf335f
1 //
2 //  DPDictionaryTests.m
3 //  HigherOrderMessaging
4 //
5 //  Created by Ofri Wolfus on 22/05/07.
6 //  Copyright 2007 Ofri Wolfus. All rights reserved.
7 //
9 #import "DPDictionaryTests.h"
10 #import "DPCollectionEnumeration.h"
13 @implementation DPDictionaryTests
15 //=============================================
16 // NOTE: Tests are executed from the bottom up
17 //=============================================
19 - (BOOL)testCollectEach {
20         NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"a", @"1",
21                                                                                                                                         @"b", @"2",
22                                                                                                                                         @"c", @"3", nil];
23         NSSet *set = [NSSet setWithObjects:@"1", @"2", @"3", nil];
24         NSDictionary *result = [NSDictionary dictionaryWithObjectsAndKeys:@"a1", @"1",
25                                                                                                                                           @"b2", @"2",
26                                                                                                                                           @"c3", @"3", nil];
27         
28         return [[dict collect:MSG(stringByAppendingString:[set each])] isEqualToDictionary:result];
31 - (BOOL)testCollect {
32         NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"a", @"1",
33                 @"b", @"2",
34                 @"c", @"3", nil];
35         NSDictionary *result = [NSDictionary dictionaryWithObjectsAndKeys:@"A", @"1",
36                 @"B", @"2",
37                 @"C", @"3", nil];
38         
39         return [[dict collect:MSG(capitalizedString)] isEqualToDictionary:result];
42 //=================================================================
43 // NOTE: All select/find + each combinations are meaningless
44 // for dictionaries as the order of objects in a dictionary
45 // can not be predicted.
46 //=================================================================
48 // There's no need to fully test rejectWhere: as it uses the
49 // same implementation of selectWhere:
50 - (BOOL)testRejectWhere {
51         NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"a", @"1",
52                 @"b", @"2",
53                 @"c", @"3", nil];
54         NSDictionary *result = [NSDictionary dictionaryWithObjectsAndKeys:@"b", @"2", @"c", @"3", nil];
55         
56         return [[dict rejectWhere:MSG(hasPrefix:@"a"), nil] isEqualToDictionary:result];
59 - (BOOL)testSelectWhere_twoMessages {
60         NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"a", @"1",
61                 @"b", @"2",
62                 @"abc", @"3", nil];
63         NSDictionary *result = [NSDictionary dictionaryWithObjectsAndKeys:@"a", @"1", @"abc", @"3", nil];
64         
65         return [[dict selectWhere:MSG(capitalizedString), MSG(hasPrefix:@"A"), nil] isEqualToDictionary:result];
68 - (BOOL)testSelectWhere_oneMessage {
69         NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"a", @"1", @"b", @"2",
70                 @"abc", @"3", nil];
71         NSDictionary *result = [NSDictionary dictionaryWithObjectsAndKeys:@"a", @"1", @"abc", @"3", nil];
72         
73         return [[dict selectWhere:MSG(hasPrefix:@"a"), nil] isEqualToDictionary:result];
76 - (BOOL)testFindObjectWhere_twoMessages {
77         NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"a", @"1", @"b", @"2",
78                 @"abc", @"3", nil];
79         return [[dict findObjectWhere:MSG(capitalizedString), MSG(hasPrefix:@"B"), nil] isEqualToString:@"b"];
82 - (BOOL)testFindObjectWhere_oneMessage {
83         NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"a", @"1", @"b", @"2",
84                 @"abc", @"3", nil];
85         return [[dict findObjectWhere:MSG(hasPrefix:@"b"), nil] isEqualToString:@"b"];
88 @end